

namespace PolicyAlgebra.Type
{
	///<summary>
	///    This class implements the association of an object with a set
	///    of permission sets (i.e. a member a set that assigns permissions 
	///    to an object).
	///</summary>
	public class ObjectPermissionSetSetAssociation : Commentable
	{ 
		private Object obj;
		private PermissionSetSet pss;

		///<summary>
		/// Constructor.
		///</summary>
		///<param name="obj">The policy object to associate a set of permission set with</param>
		///<param name="pss">The set of permission set to associate with the first parameter</param>
		public ObjectPermissionSetSetAssociation(Object obj, PermissionSetSet pss) 
			: this("", "", obj , pss) {}


		///<summary>
		/// Constructor.
		///</summary>
		///<param name="name">A name for this association</param>
		///<param name="obj">The policy object to associate a set of permission set with</param>
		///<param name="pss">The set of permission set to associate with the first parameter</param>
		public ObjectPermissionSetSetAssociation(string name, Object obj, PermissionSetSet pss) 
			: this(name, "", obj, pss) {}


		///<summary>
		/// Constructor.
		///</summary>
		///<param name="name">A name for this association</param>
		///<param name="comment">A comment for this association</param>
		///<param name="obj">The policy object to associate a set of permission set with</param>
		///<param name="pss">The set of permission set to associate with the first parameter</param>
		public ObjectPermissionSetSetAssociation(string name, string comment, Object obj, PermissionSetSet pss) 
			: base(name, comment)
		{
			this.obj = obj;
			this.pss  = pss;
		}

		///<summary>
		/// This property is used to get read acces to the object
		/// that is associated with the set of permission sets.
		///</summary>
		public Object Object
		{
			get
			{
				return obj;
			}
		}


		///<summary>
		/// This property is used to get read acces to the set of permission
		/// sets that are associated with the object.
		///</summary>
		public PermissionSetSet Pss
		{
			get
			{
				return pss;
			}
		}


		//
		// Below follows the methods that are used to compare two of these sets.


		///<summary>
		/// This operator checks two sets for equality.
		///</summary>
		///<param name="os1">The first set in the comparison</param>
		///<param name="os2">The second set in the comparison</param>
		public static bool operator ==(ObjectPermissionSetSetAssociation os1, ObjectPermissionSetSetAssociation os2)
		{
			return os1.Equals(os2);
		}


		///<summary>
		/// This operator checks two sets for inequality.
		///</summary>
		///<param name="os1">The first set in the comparison</param>
		///<param name="os2">The second set in the comparison</param>
		public static bool operator !=(ObjectPermissionSetSetAssociation os1, ObjectPermissionSetSetAssociation os2)
		{
			return !(os1 == os2);
		}


		///<summary>
		/// This method checks two sets for equality (the instance that the
		/// method is called upon and the supplied one).
		///</summary>
		///<param name="os">The supplied set for comparison</param>
		public override bool Equals(object os)
		{
			if (! (os is ObjectPermissionSetSetAssociation))
			{
				return false;
			}

			ObjectPermissionSetSetAssociation ra = (ObjectPermissionSetSetAssociation) os;

			return (this.Object == ra.Object) && (this.Pss == ra.Pss);
		}


		///<summary>
		/// Compute a hashcode for an object of this type.
		///</summary>
		///<returns>Integer hashcode</returns>
		public override int GetHashCode()
		{
			return (obj.GetHashCode() + pss.GetHashCode()); // Well, it might be good.
		}
	}
}
